package com.material.controller.supplier;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.material.common.annotation.LoginUser;
import com.material.common.base.CommonController;
import com.material.common.core.domain.entity.SysUser;
import com.material.common.entity.ResultResponse;
import com.material.contract.domain.ContractInfo;
import com.material.contract.domain.ContractTemplate;
import com.material.contract.service.IContractInfoService;
import com.material.contract.service.IContractTemplateService;
import com.material.contract.vo.ContractInfoVo;
import com.material.request.ContractQueryRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author ganxinge
 */
@Api(tags = "4.合同管理")
@RestController
@RequestMapping("/contract")
public class ContractController extends CommonController {

    @Autowired
    private IContractInfoService contractInfoService;
    @Autowired
    private IContractTemplateService contractTemplateService;

    @ApiOperation("合同列表")
    @GetMapping("/list")
    public ResultResponse list(@ApiIgnore @LoginUser SysUser sysUser, ContractQueryRequest contractQueryRequest){
        checkSupplierUser(sysUser);
        PageHelper.startPage(contractQueryRequest.getPageNum(),contractQueryRequest.getPageSize());
        ContractInfo query = new ContractInfo();
        query.setSupplierId(sysUser.getBizId());
        List<ContractInfoVo> contractInfos = contractInfoService.selectContractList(query);
        PageInfo<ContractInfoVo> pageInfo = new PageInfo<>(contractInfos);
        return ResultResponse.success(pageInfo);
    }

    @ApiOperation("合同详情")
    @GetMapping("/detail/{id}")
    public ResultResponse detail(@PathVariable("id") Long id){
        ContractInfo contractInfo = contractInfoService.selectContractInfoById(id);
        ContractTemplate contractTemplate = contractTemplateService.selectContractTemplateById(contractInfo.getTemplateId());
        //ContractDetailResponse contractDetailResponse = BeanUtil.copyProperties(contractInfo, ContractDetailResponse.class);
        //contractDetailResponse.setContent(contractTemplate.getContent());
        return ResultResponse.success(contractInfo);
    }
}
